<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\baiying\controller;

class CallBack extends \app\ApiRest
{
    protected $app;
    public function __construct(\think\App $app)
    {
        $this->app = $app;
    }
    public function outboundCallBack()
    {
        $data = request()->param();
        if(isset($data["code"]) && isset($data["data"]["callbackType"])) {
            $callbackType = $data["data"]["callbackType"];
            $insert = ["value" => json_encode($data), "callbackType" => $callbackType, "in_time" => date("Y-m-d H:i:s")];
            \app\baiying\model\BaiYingCallback::insert($insert);
            if($callbackType == "CALL_INSTANCE_RESULT" && isset($data["data"]["data"]["callInstance"])) {
                $mobile = $data["data"]["data"]["callInstance"]["customerTelephone"];
                $finishStatus = $data["data"]["data"]["callInstance"]["finishStatus"];
                $job_id = $data["data"]["data"]["callInstance"]["callJobId"];
                $voice = $data["data"]["data"]["callInstance"]["userLuyinOssUrl"];
                $info = \app\baiying\model\BaiYingPhoneRecord::where(["job_id" => $job_id, "mobile" => $mobile])->find();
                if($info) {
                    \app\baiying\model\BaiYingPhoneRecord::where(["job_id" => $job_id, "mobile" => $mobile])->update(["voice_path" => $voice, "finish_status" => $finishStatus]);
                    if($info["type"] == 2) {
                        $order_id = \app\baiying\model\BaiYingPhoneRecord::where(["job_id" => $job_id, "mobile" => $mobile, "type" => 2])->column("order_id");
                        \app\massage\model\NoPayRecord::whereIn("id", $order_id)->update(["by_status" => $finishStatus]);
                    }
                }
            }
        }
        exit("success");
    }
}

?>